package yagwl.service.fnd.flex;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import yagwl.service.util.CryptoUtil;

@SuppressWarnings("serial")
@Entity
@Table(name = "M_FLEX_ATTRIBUTE")
public class FlexAttributeEntity implements Serializable {

  private static final String entityCode = "ATTR";

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "ATTRIBUTE_ID")
  private Long attributeId;
  
  @Column(name = "NAME")
  private String name; // programmatic access name
  
  @Column(name = "DISPLAY_NAME")
  private String displayName;
  
  @Column(name = "TYPE")
  private Type type;  
  
  Long getAttributeId() {
    return attributeId;
  }

  void setAttributeId(Long attributeId) {
    this.attributeId = attributeId;
  }

  public String getEncryptedAttributeId() {
    return encryptId(attributeId);
  }

  public void setEncryptedAttributeId(String id) {
    attributeId = decryptId(id);
  }
  
  static String encryptId(Long id) {
    return CryptoUtil.encryptLong(id, entityCode);
  }

  static Long decryptId(String id) {
    return CryptoUtil.decryptLong(id, entityCode);
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getDisplayName() {
    return displayName;
  }

  public void setDisplayName(String displayName) {
    this.displayName = displayName;
  }

  public Type getType() {
    return type;
  }

  public void setType(Type type) {
    this.type = type;
  }

  public enum Type {
    Boolean, String, Integer, 
  }

}